﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
using BUS;

namespace CungMuaC5.Account_Admin
{
    public partial class DanhSachDDH : System.Web.UI.Page
    {
        private BUS_DonHang bus_DH = new BUS_DonHang();
        List<DTO_DonHangView> danhSachDH;
        protected void Page_Load(object sender, EventArgs e)
        {
            LayDanhSachDDH();
        }
        private void LayDanhSachDDH()
        {
           
            danhSachDH = bus_DH.AdLayDSDH();
            string a = "Kết quả: "+ (danhSachDH.Count).ToString();
            Label24.Text = a;
            GridView2.DataSource = danhSachDH;
            GridView2.DataBind();
        }
        protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
        {
            danhSachDH = new List<DTO_DonHangView>();
            danhSachDH = bus_DH.LayDSDHTheoNguoiDat(TextBox2.Text);
            string a = "Kết quả: " + (danhSachDH.Count).ToString();
            if (danhSachDH.Count > 0)
            {
                GridView2.DataSource = danhSachDH;
                GridView2.DataBind();
                Label24.Text = a;
            }
            else
            {
                a = "Không tìm thấy!";
                Label24.Text = a;
            }
                
        }

        protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void GridView2_SelectedIndexChanged1(object sender, EventArgs e)
        {

        }

        protected void ImageButton4_Click(object sender, ImageClickEventArgs e)
        {
            int n = danhSachDH.Count;
            for (int i = 0; i < n; i++)
            {
                CheckBox chk = (CheckBox)GridView2.Rows[i].FindControl("CheckBoxField");
                if (chk.Checked == true && danhSachDH[i].TinhTrang != true)
                {
                    danhSachDH[i].TinhTrang = true;
                    bus_DH.UpdateTinhTrang(danhSachDH[i]);
                }
                if (chk.Checked == false && danhSachDH[i].TinhTrang != false)
                {
                    danhSachDH[i].TinhTrang = false;
                    bus_DH.UpdateTinhTrang(danhSachDH[i]);
                }
            }
        }
    }
}